﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    using Model;
    using System.Data;
    using System.Data.SqlClient;
   public class DALClazz
    {
        public List<Clazz> SelectAll()
        {
            string sql = "select * from [clazz]";
            List<Clazz> list = new List<Clazz>();
            using (SqlDataReader sdr =DBHelper.ExecuteReader(sql))
            {
                while (sdr.Read())
                {
                    //Clazz c = new Clazz() { ID=值};
                    //c.ID=值
                    //list.Add(c);
                    list.Add(new Clazz() {
                        ID=sdr["ID"]==DBNull.Value?
                        (int?)null:Convert.ToInt32(sdr["ID"]),
                        CName= sdr["CName"] == DBNull.Value ? 
                        null : Convert.ToString(sdr["CName"]),
                        TID = sdr["TID"] == DBNull.Value ?
                        (int?)null : Convert.ToInt32(sdr["TID"]),
                    });
                }
            }
            return list;
        }
    }
}
